<template>
  <!-- 每一项商品 -->
	<view class="goods-item">
	  <!-- 左侧图片盒子 -->
	  <view class="goods-item-left">
      <!-- 选择框 -->
      <radio @click="handleClick(item)" :checked="item.goods_state" color="#C00000" v-if="showRadio"></radio>
	    <!-- 图片 -->
	    <image :src="item.goods_small_logo || defaultImage" class="goods-pic"></image>
	  </view>
	  <!-- 右侧商品信息盒子 -->
	  <view class="goods-item-right">
	    <!-- 商品描述 -->
	    <view class="goods-name">{{item.goods_name}}</view>
	    <!-- 商品信息 -->
	    <view class="goods-info-box">
	      <!-- 商品价格 -->
	      <view class="goods-price">￥{{item.goods_price | toFixed}}</view>
        <!-- 数量增加框 -->
        <uni-number-box v-if="showRadio" :min="1" :value="item.goods_count" @change="countChange"></uni-number-box>
	    </view>
	  </view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 默认图片
				defaultImage:'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
			};
		},
    props:{
      item:{
        type:Object,
        default:{}
      },
      showRadio: {
        type:Boolean,
        default:false
      },
    },
    // 过滤器，使价格保留两位小数
    filters:{
      toFixed(num) {
        return Number(num).toFixed(2)
      }
    },
    methods:{
      handleClick(goods) {
        this.$emit('radioChange',{
          goods_id:goods.goods_id,
          goods_state:!goods.goods_state
        })
      },
      countChange(newCount) {
        this.$emit('numChange',{
          goods_id:this.item.goods_id,
          goods_count:+newCount
        })
      }
    }
	}
</script>

<style lang="scss">
.goods-item {
  display: flex;
  padding: 10px 5px;
  border-bottom: 1px solid #efefef;
  .goods-item-left {
    margin-right: 5px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .goods-pic {
      width: 100px;
      height: 100px;
      margin-right: 5px;
    }
  }
  .goods-item-right {
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: space-between;
    .goods-name {
      font-size: 13px;
    }
    .goods-info-box {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .goods-price {
        font-size: 16px;
        color: #C00000;
      }
    }
  }
}
</style>
